package com.self.campussecondhandmarket.resp;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

/**
 * Author: Vincent
 * <p> DateTime: 2024/2/13 22:12
 * <p> Description: 结果集统一
 * <p>
 **/
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Result<T> {
	
	private Integer code;
	private String msg;
	private T data;
	
	public Result(Status status, T data) {
		this.code = status.code();
		this.msg = status.msg();
		this.data = data;
		
	}
	
	public Result(Status status) {
		this.code = status.code();
		this.msg = status.msg();
	}
	
	// -------------------  结果集返回  ----------------
	public static <T> Result<T> success(T t) {
		return new Result<T>(Code.SUCCESS, t);
	}
	
	public static <T> Result<T> error(T t) {
		return new Result<T>(Code.FAIL, t);
	}
	
	public static <T> Result<T> success() {
		return new Result<T>(Code.SUCCESS);
	}
	
	public static <T> Result<T> error() {
		return new Result<T>(Code.FAIL);
	}
	
}
